package zy2;

import java.util.Scanner;

/*
* 1. 模拟电视商品价格竞猜活动
* */
public class GuessMachine {
    /*
    * 电视商品列表
    小米电视    3399.00
    LG电视     5999.00
    海尔电视    12999.00
    * */

    double millet = 3399.00;
    double LG = 5999.00;
    double Haier = 12999.00;

    public void init(int num){
        switch (num){
            case 1:
                System.out.println("小米电视");
                break;
            case 2:
                System.out.println("LG电视");
                break;
            case 3:
                System.out.println("海尔电视");
                break;
        }
    }

     public boolean guess(double money,int num){
        boolean flag = false;
        if (num==1) {
                if (money == millet) {                      //小米电视
                    flag = true;
                    System.out.println("恭喜您，猜对了！");
                } else if (money - millet > 399) {
                    flag = false;
                    System.out.println("再小一些!");
                } else if (millet - money <= 399) {
                    flag = false;
                    System.out.println("再大一些!");
                }
            }

         if (num==2) {
                 if (money == LG) {                      //LG电视
                     flag = true;
                     System.out.println("恭喜您，猜对了！");
                 } else if (money - LG > 999) {
                     flag = false;
                     System.out.println("再小一些!");
                 } else if (LG - money <= 999) {
                     flag = false;
                     System.out.println("再大一些!");
                 }
             }

         if (num==3) {
                 if (money == Haier) {                      //海尔电视
                     flag = true;
                     System.out.println("恭喜您，猜对了！");
                 } else if (money - Haier > 999) {
                     flag = false;
                     System.out.println("再小一些!");
                 } else if (Haier - money <= 999) {
                     flag = false;
                     System.out.println("再大一些!");
                 }
            }
         return flag;
        }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        GuessMachine chine = new GuessMachine();
        int num = (int)(Math.random()*3+1);
        chine.init(num);

        for (int i = 3; i >= 1; i--) {
            System.out.println("请您竞猜商品价格:");
            double money = input.nextDouble();
            if (chine.guess(money,num)){
                break;
            }
            if (i != 1){
                System.out.println("您还有"+(i-1)+"次机会");
            }else {
                System.out.println("下次努力!");
            }
        }
    }
}
